package com.ck.roomdemo.room;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

@Database(entities = {Student.class}, version = 1, exportSchema = false)
public abstract class MyDatabase extends RoomDatabase {
    // 单例 singleton
    private static MyDatabase INSTANCE;
    public static synchronized MyDatabase getDatabase(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                    MyDatabase.class, "myDatabase")
                    .build();
        }
        return INSTANCE;
    }

    public abstract StudentDao getStudentDao();
}
